﻿using DevExpress.XtraBars;
using Inaction.Message;
using Inaction.UI.Common;
using System;
using System.Windows.Forms;

namespace Inaction.UI.Extensions.BarExtensions
{
    public class ResetLayoutExtender
    {
        public static void Extend(BarManager barManager, BarItemLinkCollection links)
        {
            var item = new BarSubItem(barManager, "窗体布局");
            var resetFormLayoutItem = new BarButtonItem(barManager, "重置本窗体布局");
            var resetAllLayoutItem = new BarButtonItem(barManager, "重置所有窗体布局");
            item.AddItem(resetFormLayoutItem);
            item.AddItem(resetAllLayoutItem);
            links.Add(item, true);

            resetFormLayoutItem.ItemClick += (s, a) =>
                {
                    LayoutHelper.ResetLayout(barManager.Form as Form);
                    MessageHost.ShowMessage(barManager.FormManager.Form.Text + ":重置窗体布局完成");
                };

            resetAllLayoutItem.ItemClick += (sender, e) =>
                {
                    var message = "重置所有窗体布局后,当前打开的窗口都不会保存布局," + Environment.NewLine
                + "打开的窗口在系统下次登陆后才可调整并保存布局" + Environment.NewLine
                + "您确定要重置所有窗体布局吗?";
                    if (MessageBox.Show(message, "系统提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                    {
                        LayoutHelper.ResetLayoutAll();
                        MessageHost.ShowMessage("重置所有窗体布局完成");
                    }
                };
        }
    }
}
